<?php

namespace app\admin\model;

use think\facade\Db;

class Profit extends BaseModel
{
    protected $name = "distribution_price";

    public function getInfo($id)
    {
        $info = Db::name('distribution_price')->where('id', $id)->find();

        $info['price'] = $info['price'] . '元';
        switch ($info['type']) {
            case 1:
                $order = Db::name('customer_order')->where('id', $info['order_id'])->find();
                $user = Db::name('member')->where('id', $order['user_id'])->find();
                $order['price'] = $order['pay_price'];
                break;
            case 2:
                $order = Db::name('customer_level_order')->where('id', $info['order_id'])->find();

                $user = Db::name('member')->where('id', $order['user_id'])->find();
                break;
            case 3:
                $order = Db::name('customer_seat_order')->where('id', $info['order_id'])->find();

                $user = Db::name('member')->where('id', $order['user_id'])->find();
                break;
            case 4:
                $order = Db::name('customer_recharge_order')->where('id', $info['order_id'])->find();

                $user = Db::name('member')->where('id', $order['user_id'])->find();
                break;
            case 5:
                $order = Db::name('customer_integral_product_order')->where('id', $info['order_id'])->find();
                $order['price'] = $order['pay_money'];
                $user = Db::name('member')->where('id', $order['user_id'])->find();
                break;
            case 6:
                $order = Db::name('customer_order')->where('id', $info['order_id'])->find();
                $order['price'] = $order['pay_price'] - $order['retreat_price'];
                $user = Db::name('member')->where('id', $order['user_id'])->find();
                break;
        }
        $info['order_price'] = $order['price'] . '元';
        $info['nickname'] = $user['nickname'];
        $info['mobile'] = $user['mobile'];
        $roomlist = Db::name('mini_room_list')->where('id', $info['direct_id'])->find();
        if ($roomlist) {
            $info['referrer'] = $roomlist['room_name'];

        }
        $info['direct_name'] = '';
        $info['direct_price'] = 0;
        if ($info['second_id'] > 0) {
            $roomlist = Db::name('mini_room_list')->where('id', $info['second_id'])->find();

            if ($roomlist) {
                $info['direct_name'] = $roomlist['room_name'];
            }
        }
        $info['second_name'] = '';
        $info['level_price'] = 0;
        if ($info['leve_id'] > 0) {
            $roomlist = Db::name('mini_room_list')->where('id', $info['leve_id'])->find();

            if ($roomlist) {
                $info['second_name'] = $roomlist['room_name'];

                $info['direct_name'] = $roomlist['room_name'];
            }
        }


        return $info;
    }
}